﻿using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FineUI;
using Maticsoft.Common;

namespace lcmyjobs.Web.enprise
{
    public partial class PostJobs : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                txtjobclass.Attributes.Add("readonly", "true");
                txtarea.Attributes.Add("readonly", "true");
                txtmajor.Attributes.Add("readonly", "true");                
                if (Application["webname"] != null)
                {
                    this.Title = string.Format("单位管理中心—职位管理：发布职位  {0}", Application["webname"].ToString());
                }
                if (Session["enterprise_name"] != null)
                {
                    this.lbl_title.Text = " " + Session["enterprise_name"];
                }
                else
                {
                    Maticsoft.Common.MessageBox.ShowAndRedirect(this, "请先登陆！", "EnterpriseLogin.html");
                }
            }
        }

        //发布职位
        protected void btn_postjob_Click(object sender, EventArgs e)
        {
            int enterprise_bid = -1;

            if (Session["jobsCount"] != null && Session["enterprise_bid"] != null)
            {
                enterprise_bid = Convert.ToInt32(Session["enterprise_bid"]);

                lcmyjobs.Model.jobsCount jc = Session["jobsCount"] as lcmyjobs.Model.jobsCount;

                
                    if (this.cbo_isfrist.Checked)//如果是急聘职位
                    {
                        #region 急聘职位会员权限计算
                        if (jc.fristJobCount - jc.isFristJobsCount > 0)//判断是否可以发布此急聘职位
                        {
                            if (Save(enterprise_bid))
                            {
                                jc.isFristJobsCount = jc.isFristJobsCount + 1;//使已发的急聘布职位加1
                                jc.jobsPubCount = jc.jobsPubCount + 1;//使已发布职位加1
                                Session["jobsCount"] = jc;//记录到session中
                                Maticsoft.Common.MessageBox.ShowAndRedirect(this, "发布急聘职位成功！", "PostJobs.html");
                            }
                            else
                            {
                                Maticsoft.Common.MessageBox.ShowAndRedirect(this, "发布急聘职位失败！", "PostJobs.html");
                            }
                        }
                        else
                        {
                            Maticsoft.Common.MessageBox.ShowAndRedirect(this, "您的会员权限所能发布的急聘职位已用完，或者您没有权限发布急聘职位！请您升级会员后再次发布。", "ListMember.html");
                        }
                        #endregion
                    }
                    else
                    {
                        #region 非急聘职位会员权限计算
                        

                            if (Save(enterprise_bid))
                            {
                                //jc.jobsPubCount = jc.jobsPubCount + 1;//使已发布职位加1
                                Session["jobsCount"] = jc;//记录到session中
                                Maticsoft.Common.MessageBox.ShowAndRedirect(this, "发布职位成功！", "PostJobs.html");
                            }
                            else
                            {
                                Maticsoft.Common.MessageBox.ShowAndRedirect(this, "发布职位失败！", "PostJobs.html");
                            }
                       
                        #endregion

                    }              

            }
            else
            {
                Maticsoft.Common.MessageBox.ShowAndRedirect(this, "由于长时间未操作，登陆已过期！请重新登录", "EnterpriseLogin.html");
            }




        }

        private bool Save(int enterprise_bid)
        {
            if (Page.IsValid)
            {
                //int enterprise_bid = int.Parse(this.txtenterprise_bid.Text);
                //string enterprise_bh = this.txtenterprise_bh.Text;
                //int jobs_id = int.Parse(this.txtjobs_id.Text);
                string hid_jobclass = this.hid_jobclass.Value;
                string jobs_name = this.txtjob.Text;
                string jobclass = this.txtjobclass.Text;
                int workercount = int.Parse(this.txtworkercount.Text);
                string jobdep = this.txtjobdep.Text;
                string salarym = this.ddlsalarym.SelectedItem.Value;
                string salaryy = "";
                /*
                if (!string.IsNullOrEmpty(this.txtsalaryy.Text))
                {
                    salaryy = this.txtsalaryy.Text;
                }
                 */
                int minsal = 0, maxsal = 0;
                minsal = int.Parse(txtYmin.Text.ToString());
                maxsal = int.Parse(txtYmax.Text.ToString());

                int validity = int.Parse(this.txtvalidity.Text);
                int workerclass = -1;

                if (this.rdo_bx.Checked)
                {
                    workerclass = 0;
                }
                if (this.rdo_wjs.Checked)
                {
                    workerclass = 1;//往届生
                }
                if (this.rdo_yjs.Checked)
                {
                    workerclass = 2;//应届生
                }

                int edus_id = int.Parse(this.ddledus_id.SelectedItem.Value);
                int workexp_id = int.Parse(this.ddlworkxp_id.SelectedItem.Value);
                string jobduty = this.txtjobduty.Text;
                string jobrequirement = this.txtjobrequirement.Text;
                DateTime releasetime = DateTime.Now;//职位发布日期
                bool isuse = true;//是否激活0、屏蔽，1、激活
                int languages_id = int.Parse(this.ddllanguage.SelectedItem.Value);
                string languages_level = this.ddllanguageslevel.SelectedItem.Value;//外语水平
                int bcount = 0;//浏览次数
                bool isfrist = false;//是否急聘0、否，1、是

                if (this.cbo_isfrist.Checked)
                {
                    isfrist = true;
                }

                int status = 0;

                string area_name1 = "0";
                string area_name2 = "0";
                string area_name3 = "0";
                string marjor_name1 = "0";
                string marjor_name2 = "0";
                string marjor_name3 = "0";


                string[] area_names = this.txtarea.Text.Split(',');

                if (area_names.Length == 0)
                {
                    area_name1 = this.txtarea.Text;
                }
                if (area_names.Length == 1)
                {
                    area_name1 = area_names[0];
                }
                if (area_names.Length == 2)
                {
                    area_name1 = area_names[0];
                    area_name2 = area_names[1];
                }
                if (area_names.Length == 3)
                {
                    area_name1 = area_names[0];
                    area_name2 = area_names[1];
                    area_name3 = area_names[2];
                }

                string majors = "";

                if (this.cbo_bx.Checked)
                {
                    majors = "专业不限";
                }
                else
                {
                    majors = this.txtmajor.Text;
                }

                string[] major_names = majors.Split(',');


                if (major_names.Length == 0)
                {
                    marjor_name1 = this.txtmajor.Text;
                }
                if (major_names.Length == 1)
                {
                    marjor_name1 = major_names[0];
                }
                if (major_names.Length == 2)
                {
                    marjor_name1 = major_names[0];
                    marjor_name2 = major_names[1];
                }
                if (major_names.Length == 3)
                {
                    marjor_name1 = major_names[0];
                    marjor_name2 = major_names[1];
                    marjor_name3 = major_names[2];
                }

                float rewardmoney = -1f;

                if (this.cbo_isreward.Checked)
                {
                    rewardmoney = float.Parse(this.txtrewardpay.Text);
                }



                lcmyjobs.Model.enterprise_releasejob model = new lcmyjobs.Model.enterprise_releasejob();
                model.enterprise_bid = enterprise_bid;
                //model.enterprise_bh = enterprise_bh;
                //model.jobs_id = jobs_id;
                model.jobs_name = jobs_name;
                model.jobclass = hid_jobclass;//工作类别父类名
                model.job_child_class = jobclass;//工作类别子类名
                model.workercount = workercount;
                model.jobdep = jobdep;
                model.salarym = salarym;
                model.salaryymin = minsal;
                model.salaryymax=maxsal;
                model.validity = validity;
                model.workerclass = workerclass;
                model.edus_id = edus_id;
                model.workexp_id = workexp_id;
                model.jobduty = jobduty;
                model.jobrequirement = jobrequirement;
                model.releasetime = releasetime;
                model.isuse = isuse;
                model.languages_id = languages_id;
                model.bcount = bcount;
                model.isfrist = isfrist;
                model.status = status;
                model.languages_level = languages_level;
                model.area_name1 = area_name1;
                model.area_name2 = area_name2;
                model.area_name3 = area_name3;
                model.marjor_name1 = marjor_name1;
                model.marjor_name2 = marjor_name2;
                model.marjor_name3 = marjor_name3;
                model.rewardmoney = rewardmoney;


                lcmyjobs.BLL.enterprise_releasejob bll = new lcmyjobs.BLL.enterprise_releasejob();
                if (bll.Add(model) > 0)
                {
                    return true;
                }
                else
                {
                    return false;

                }
            }
            else
            {
                return false;
            }
        }

        protected void btn_why_Click(object sender, EventArgs e)
        {

            //Alert alert = new Alert();
            string msg = "<div style='width:250px;text-indent:2em; line-height:20px;'><p style='padding-Bottom:5px; '>  悬赏招聘：更准确、更快捷、更低成本。</p>";
            msg += "<p style='padding-Bottom:5px; '>  更准确----提供专业的人才选择工具，帮助企业深度甄选人才。 基于人才胜任素质的评测工具辅助人才选择。颠覆被动“等待”人才的传统方式。</p>";
            msg += "<p style='padding-Bottom:5px; '>  更快捷----发挥社会力量，动员群众，借助猎手人脉资源关系，让您的悬赏信息迅速覆盖目标群体，快速找到适合人才。</p>";
            msg += "<p>  更低成本----悬赏招聘使企业能够以较低的价格完成猎头服务。悬赏企业自行定价、发布有效职位，成本仅为传统猎头费用(费用为该职位年薪的30%)的十分之一，甚至更低，并全程享受专业人事招聘服务，轻松猎才。</p></div>";

            msg = "悬赏招聘：更准确、更快捷、更低成本。<br/><br/>更准确----提供专业的人才选择工具，帮助企业深度甄选人才。 基于人才胜任素质的评测工具辅助人才选择。颠覆被动“等待”人才的传统方式。<br/><br/>更快捷----发挥社会力量，动员群众，借助猎手人脉资源关系，让您的悬赏信息迅速覆盖目标群体，快速找到适合人才。<br/><br/>更低成本----悬赏招聘使企业能够以较低的价格完成猎头服务。悬赏企业自行定价、发布有效职位，成本仅为传统猎头费用(费用为该职位年薪的30%)的十分之一，甚至更低，并全程享受专业人事招聘服务，轻松猎才。";
            /*
            alert.Message = msg;
            alert.Icon = Icon.Help;
            alert.Title = "为什么要悬赏招聘";
            alert.Show();
            */
            Alert.Show(msg);
            //Maticsoft.Common.MessageBox.Show(this, msg);
        }
    }
}